<?php
/*
 * $Id: contact_us.php,v 1.5 2010/02/02 Spooks Exp $ osCommerce, Open Source
 * E-Commerce Solutions http://www.oscommerce.com Copyright (c) 2010 osCommerce
 * Released under the GNU General Public License
 */

require ('includes/application_top.php');
require (DIR_WS_LANGUAGES . $language . '/' . FILENAME_CONTACT_US);

$error = false;
if (isset ( $_GET ['action'] ) && ($_GET ['action'] == 'send')) {
	$name = tep_db_prepare_input ( $_POST ['name'] );
	$email = tep_db_prepare_input ( $_POST ['email'] );
	$enquiry = tep_db_prepare_input ( $_POST ['enquiry'] );
	$subject = tep_db_prepare_input ( $_POST ['subject'] );
	$phone = tep_db_prepare_input ( $_POST ['phone'] );
	$date = 'Date Sent: ' . date ( "d M Y H:i:s" );
	$orders_id = tep_not_null ( $_POST ['orders_id'] ) ? $_POST ['orders_id'] : false;
	$xipaddress = $_SERVER ["REMOTE_ADDR"];
	$subject = $subject ? $subject : EMAIL_SUBJECT;
	
	// $enquiry = preg_replace('/\r/','\', \'',$enquiry);
	// $enquiry = preg_replace('/\(|\)/','\'',$enquiry);
	// $_POST['enquiry'] = $result;
	
	if (strlen ( $name ) < ENTRY_LAST_NAME_MIN_LENGTH) {
		$error = true;
		
		$messageStack->add ( 'contact', ENTRY_LAST_NAME_ERROR );
	}
	if (strlen ( $enquiry ) < 8) {
		$error = true;
		
		$messageStack->add ( 'contact', ENTRY_ERROR_ENQUIRY );
	}
	if (! tep_validate_email ( $email )) {
		$error = true;
		
		$messageStack->add ( 'contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR );
	}
	if (! $error) {
		$enquiry = MESSAGE_FROM . $name . "\n" . $date . "\n" . ($phone ? ENTRY_TELEPHONE_NUMBER . $phone . "\n" : '') . ($customer_id ? MAIL_CLIENT_ID . $customer_id . "\n" : '') . ($orders_id ? MAIL_ORDER_ID . $orders_id . "\n" : '') . "\n" . MAIL_IP . $xipaddress . '.' . "\n\n" . ENTRY_ENQUIRY . "\n" . $enquiry;
		tep_mail ( STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS, $subject, $enquiry, $name, $email );
		
		tep_redirect ( tep_href_link ( FILENAME_CONTACT_US, 'action=success' ) );
	}
}

$breadcrumb->add ( NAVBAR_TITLE, tep_href_link ( FILENAME_CONTACT_US ) );
?>
  <?php
		/*
		 * $Id$ osCommerce, Open Source E-Commerce Solutions
		 * http://www.oscommerce.com Copyright (c) 2010 osCommerce Released
		 * under the GNU General Public License
		 */
		
		$oscTemplate->buildBlocks ();
		
		if (! $oscTemplate->hasBlocks ( 'boxes_column_left' )) {
			$oscTemplate->setGridContentWidth ( $oscTemplate->getGridContentWidth () + $oscTemplate->getGridColumnWidth () );
		}
		
		if (! $oscTemplate->hasBlocks ( 'boxes_column_right' )) {
			$oscTemplate->setGridContentWidth ( $oscTemplate->getGridContentWidth () + $oscTemplate->getGridColumnWidth () );
		}
		?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type"
	content="text/html; charset=<?php echo CHARSET; ?>" />
<title><?php echo tep_output_string_protected($oscTemplate->getTitle()); ?></title>
<base
	href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>" />
<link rel="stylesheet" type="text/css"
	href="ext/jquery/ui/redmond/jquery-ui-1.8.6.css" />
<script type="text/javascript" src="ext/jquery/jquery-1.4.2.min.js"></script>
<script type="text/javascript"
	src="ext/jquery/ui/jquery-ui-1.8.6.min.js"></script>

<?php
if (tep_not_null ( JQUERY_DATEPICKER_I18N_CODE )) {
	?>
<script type="text/javascript"
	src="ext/jquery/ui/i18n/jquery.ui.datepicker-<?php echo JQUERY_DATEPICKER_I18N_CODE; ?>.js"></script>
<script type="text/javascript">
$.datepicker.setDefaults($.datepicker.regional['<?php echo JQUERY_DATEPICKER_I18N_CODE; ?>']);
</script>
<?php
}
?>

<script type="text/javascript"
	src="ext/jquery/bxGallery/jquery.bxGallery.1.1.min.js"></script>
<link rel="stylesheet" type="text/css"
	href="ext/jquery/fancybox/jquery.fancybox-1.3.4.css" />
<script type="text/javascript"
	src="ext/jquery/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<link rel="stylesheet" type="text/css"
	href="ext/960gs/<?php echo ((stripos(HTML_PARAMS, 'dir="rtl"') !== false) ? 'rtl_' : ''); ?>960_24_col.css" />
<link rel="stylesheet" type="text/css" href="stylesheet.css" />
<link rel="stylesheet" type="text/css"
	href="ext/category_menu/category_menu.css" />
<?php echo $oscTemplate->getBlocks('header_tags'); ?>
</head>
<body>

<div id="bodyWrapper"
	class="container_<?php echo $oscTemplate->getGridContainerWidth(); ?>">

<?php require(DIR_WS_INCLUDES . 'header.php'); ?>

<div id="bodyContent"
	class="grid_<?php echo $oscTemplate->getGridContentWidth(); ?> <?php echo ($oscTemplate->hasBlocks('boxes_column_left') ? 'push_' . $oscTemplate->getGridColumnWidth() : ''); ?>"
	style="margin-left: 18px; width: 924px; height: 100%; background-color: white;">
  
  <?php
		// require(DIR_WS_INCLUDES . 'template_top.php');
		$account = array ();
		$orders = array ();
		$name = '';
		$email = '';
		$phone = '';
		if (tep_session_is_registered ( 'customer_id' )) {
			$account_query = tep_db_query ( "select customers_firstname, customers_lastname, customers_telephone, customers_id, customers_email_address from " . TABLE_CUSTOMERS . " where customers_id = '" . ( int ) $customer_id . "'" );
			$account = tep_db_fetch_array ( $account_query );
			$name = $account ['customers_firstname'] . ' ' . $account ['customers_lastname'];
			$email = $account ['customers_email_address'];
			$phone = $account ['customers_telephone'];
			$history_query = tep_db_query ( "select orders_id, date_purchased from " . TABLE_ORDERS . " where customers_id = '" . ( int ) $customer_id . "' order by orders_id DESC" );
			$orders [0] = array (
					'id' => '0',
					'text' => ENTRY_ORDER_ID 
			);
			while ( $history = tep_db_fetch_array ( $history_query ) ) {
				$orders [] = array (
						'id' => $history ['orders_id'],
						'text' => $history ['orders_id'] . ENTRY_ORDERED . tep_date_short ( $history ['date_purchased'] ) 
				);
			}
		}
		echo tep_draw_form ( 'contact_us', tep_href_link ( FILENAME_CONTACT_US, 'action=send' ) );
		?>
	<table border="0" summary="" width="100%" cellspacing="0"
	cellpadding="0">
<tr>
<td><table border="0" summary="" width="100%" cellspacing="0"
	cellpadding="0">
<tr>
<td class="pageHeading" style="color: black;"><?php echo HEADING_TITLE; ?></td>
</td>
</tr>
</table></td>
</tr>
 <?php
	if ($messageStack->size ( 'contact' ) > 0) {
		?>
      <tr>
<td><?php echo $messageStack->output('contact'); ?></td>
</tr>
<?php
	}
	
	if (isset ( $_GET ['action'] ) && ($_GET ['action'] == 'success')) {
		?>
      <tr>
<br> <td class="pageHeading" align="center"><?php echo TEXT_SUCCESS; ?></td>

</tr>
<tr>
<td><table border="0" summary="" width="100%" cellspacing="1"
	cellpadding="2" class="infoBox">
<tr class="infoBoxContents">
<td><table border="0" summary="" width="100%" cellspacing="0"
	cellpadding="2">
<tr>
<div class="buttonSet">
					<?php echo tep_draw_button(IMAGE_BUTTON_CONTINUE, 'triangle-1-e', tep_href_link(FILENAME_DEFAULT)); ?>
			   </div>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<?php
	} else {
		echo tep_draw_hidden_field ( 'phone', $phone );
		?>
      <tr>
<td><table border="0" summary="" width="100%" cellspacing="1"
	cellpadding="2" class="infoBoxContactUs">
<tr class="infoBoxContents">
<td valign="top" width="40%"> <table>
<tr>
<td class="main"> <b><?php echo nl2br(STORE_NAME_ADDRESS); ?></b><br><br>
                <?php echo (OPENING_HOURS); ?>
								</td>
</tr>
</table>
</td>
<td valign="top" align="right"> <iframe width="425" height="350"
	frameborder="0" scrolling="no" marginheight="0" marginwidth="0"
	src="https://maps.google.com/maps?oe=utf-8&amp;client=firefox-a&amp;q=24+Nguy%E1%BB%85n+Th%C3%A1i+H%E1%BB%8Dc+-+Ba+%C4%90%C3%ACnh+-+H%C3%A0+N%E1%BB%99i+map&amp;ie=UTF8&amp;hq=&amp;hnear=24+Nguy%E1%BB%85n+Th%C3%A1i+H%E1%BB%8Dc,+%C4%90i%E1%BB%87n+Bi%C3%AAn,+Ba+Dinh+District,+Hanoi&amp;gl=vn&amp;t=m&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe>
</br> <a
	href="https://maps.google.com/maps?oe=utf-8&amp;client=firefox-a&amp;q=24+Nguy%E1%BB%85n+Th%C3%A1i+H%E1%BB%8Dc+-+Ba+%C4%90%C3%ACnh+-+H%C3%A0+N%E1%BB%99i+map&amp;ie=UTF8&amp;hq=&amp;hnear=24+Nguy%E1%BB%85n+Th%C3%A1i+H%E1%BB%8Dc,+%C4%90i%E1%BB%87n+Bi%C3%AAn,+Ba+Dinh+District,+Hanoi&amp;gl=vn&amp;t=m&amp;z=14&amp;iwloc=A&amp;source=embed"
	style="color: #0000FF; text-align: left;">View Larger Map</a>
</td>
</tr>
</table></td>
</tr>
<?php
	}
	?>
    </table>
</form>
</td>
<?php
require (DIR_WS_INCLUDES . 'template_bottom.php');
require (DIR_WS_INCLUDES . 'application_bottom.php');
?>
